#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,l,V,ans,llans;
int d[100010],v[100010],a[100010],p[100010];
bool flag[1000010];
vector<int> ve;
bool check()
{
    for(int i = 0;i < ve.size();i++) flag[ve[i]] = 1;
    int lans = 0;
    for(int i = 1;i <= n;i++)
    {
        bool f = true;
        if(v[i] > V && a[i] >= 0)
        {
            for(int j = d[i];j <= l && f;j++)
            {
                if(flag[j] == 1)
                {
                    lans++;
                    f = false;
                }
            }
        }
        if(v[i] > V && a[i] < 0)
        {
            double t = (v[i] - V) / ((0 - a[i]) * 1.0);
            double s = v[i] * t + 0.5 * a[i] * t * t;
            for(int j = d[i];j <= d[i] + s && f;j++)
            {
                if(flag[j] == 1)
                {
                    lans++;
                    f = false;
                }
            }
        }
        if(v[i] <= V && a[i] > 0)
        {
            double t = (V - v[i]) / (a[i] * 1.0);
            double s = v[i] * t + 0.5 * a[i] * t * t;
            for(int j = (int(s) == s ? int(s) : int(s) + 1);j <= l && f;j++)
            {
                if(flag[j] == 1)
                {
                    lans++;
                    f = false;
                }
            }
        }
    }
    if(ans == lans) return true;
    return false;
}
int dfs(int pos,int cnt)
{
    if(m - cnt <= llans) return 0;
    if(pos == m + 1)
    {
        if(check()) return cnt;
        return 0;
    }
    int x = dfs(pos + 1,cnt + 1);
    ve.push_back(p[pos]);
    flag[p[pos]] = 1;
    int y = dfs(pos + 1,cnt);
    ve.pop_back();
    flag[p[pos]] = 0;
    return llans = max(x,y);
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T; scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&n,&m,&l,&V);
        for(int i = 1;i <= n;i++) scanf("%d%d%d",&d[i],&v[i],&a[i]);
        for(int i = 1;i <= m;i++)
        {
            scanf("%d",&p[i]);
            flag[p[i]] = 1;
        }
        ans = 0;
        for(int i = 1;i <= n;i++)
        {
            bool f = true;
            if(v[i] > V && a[i] >= 0)
            {
                for(int j = d[i];j <= l && f;j++)
                {
                    if(flag[j] == 1)
                    {
                        ans++;
                        f = false;
                    }
                }
            }
            if(v[i] > V && a[i] < 0)
            {
                double t = (v[i] - V) / ((0 - a[i]) * 1.0);
                double s = v[i] * t + 0.5 * a[i] * t * t;
                for(int j = d[i];j <= d[i] + s && f;j++)
                {
                    if(flag[j] == 1)
                    {
                        ans++;
                        f = false;
                    }
                }
            }
            if(v[i] <= V && a[i] > 0)
            {
                double t = (V - v[i]) / (a[i] * 1.0);
                double s = v[i] * t + 0.5 * a[i] * t * t;
                for(int j = (int(s) == s ? int(s) : int(s) + 1);j <= l && f;j++)
                {
                    if(flag[j] == 1)
                    {
                        ans++;
                        f = false;
                    }
                }
            }
        }
        for(int i = 1;i <= m;i++) flag[p[i]] = 0;
        llans = 0;
        printf("%d %d\n",ans,dfs(1,0));
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
